﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DLL.FlushRobot.MS.Run
{
    public class COneInjector
    {
        public double InjectHadVolume = 0;//注射器内有的溶媒量   也就是使用的容积
        public double InjectResidualVolume = 20;//注射器内剩余的空间体积  
        public double InjectHadAirVolume = 0;//注射器有空气的体积
    }
    public class CMultyInjectors
    {
        public CMultyInjectors(double injectorMaxML,int colNum)
        {
            InjectorMaxML=injectorMaxML;
            StationColNum=colNum;
            for (int i = 0; i<MaxColPointCount; i++)
            {
                COneInjector oneInjector = new COneInjector();
                oneInjector.InjectResidualVolume=injectorMaxML;
                injectors[i]=oneInjector;
            }
        }
        static int MaxColPointCount = 8;
        public double InjectorMaxML = 0;
        public int StationColNum = 6;
        public COneInjector[] injectors = new COneInjector[MaxColPointCount];
        public double[] InjectorHadAirVolume = new double[MaxColPointCount];//冲刷自一次注入空气体积

        public void ResetInjectorHadAirVolume()
        {
            for (int i = 0; i < MaxColPointCount; i++)
            {
                InjectorHadAirVolume[i] = 0;
                injectors[i].InjectHadAirVolume=0;
            }
        }
        public void ResetInjectorHadAirVolume(int[] validCol)
        {
            for (int i = 0; i < StationColNum; i++)
            {
                if(1==validCol[i])
                {
                    InjectorHadAirVolume[i] = 0;
                    injectors[i].InjectHadAirVolume=0;
                }                
            }
        }
        public void SetInjectorHadAirVolume(double[] ml, int[] validCol)
        {
            for (int i = 0; i < StationColNum; i++)
            {
                if (validCol[i] == 1)
                {
                    InjectorHadAirVolume[i] = ml[i];
                    injectors[i].InjectHadAirVolume = ml[i];
                }

            }
        }

        public void ResetInjectHadVolume()
        {
            for (int i = 0; i<MaxColPointCount; i++)
            {
                injectors[i].InjectHadVolume = 0;
                injectors[i].InjectResidualVolume = InjectorMaxML;
            }
        }
        public void ResetInjectHadVolume(int[] validCol)
        {
            for (int i = 0; i<StationColNum; i++)
            {
                if(validCol[i]==1)
                {
                    injectors[i].InjectHadVolume = 0;
                    injectors[i].InjectResidualVolume = InjectorMaxML;
                }
                
            }
        }
        public void SetInjectHadVolume(double[] CurrentRowUsedVolume, int[] validCol, int Out = 1)
        {
            for (int i = 0; i < StationColNum; i++)
            {
                if (1 == validCol[i])
                {
                    if (1 == Out)
                    {
                        injectors[i].InjectHadVolume = injectors[i].InjectHadVolume + CurrentRowUsedVolume[i];
                    }
                    else
                    {
                        injectors[i].InjectHadVolume = injectors[i].InjectHadVolume - CurrentRowUsedVolume[i];
                    }
                    //injectors[i].InjectResidualVolume = InjectorMaxML - injectors[i].InjectHadVolume;
                }
            }
        }

        public void ResetInjector()
        {
            for (int i = 0; i<MaxColPointCount; i++)
            {
                injectors[i].InjectHadVolume = 0;
                injectors[i].InjectHadAirVolume=0;
                injectors[i].InjectResidualVolume = InjectorMaxML;
                InjectorHadAirVolume[i]=0;
            }
        }
        public void ResetInjector(int[] validCol)
        {
            for (int i = 0; i<StationColNum; i++)
            {
                if(1==validCol[i])
                {
                    injectors[i].InjectHadVolume = 0;
                    injectors[i].InjectHadAirVolume=0;
                    injectors[i].InjectResidualVolume = InjectorMaxML;
                    InjectorHadAirVolume[i]=0;
                }                
            }
        }

        public double[] GetInjectHadUsedVolume()
        {
            double[] hadUsedVolume = new double[MaxColPointCount];
            for (int i = 0; i < MaxColPointCount; i++)
            {
                hadUsedVolume[i]=injectors[i].InjectHadVolume;
            }
            return hadUsedVolume;
        }
        //获取注射器剩余容积
        public double[] GetInjectResidualVolume()
        {
            double[] residualVolume = new double[MaxColPointCount];
            for (int i = 0; i < MaxColPointCount; i++)
            {
                if(injectors[i].InjectHadVolume==0)
                {
                    residualVolume[i] = InjectorMaxML;
                }
                else
                {
                    double sub= InjectorMaxML - injectors[i].InjectHadAirVolume - injectors[i].InjectHadVolume;
                    if(sub<0)
                    {
                        sub=0;
                    }
                    residualVolume[i] = sub;
                }                
            }
            return residualVolume;
        }
        public int[]    GetHadVolumeFlag()
        {
            int[] hadVolumeFlag = new int[MaxColPointCount];
            for (int i = 0; i < MaxColPointCount; i++)
            {
                if(injectors[i].InjectHadVolume>0)
                {
                    hadVolumeFlag[i] = 1;
                }
                else
                {
                    hadVolumeFlag[i] = 0;
                }
            }
            return hadVolumeFlag;
        }
    }
}
